package com.shou.zhnfyxt.controller;

import com.shou.zhnfyxt.service.OssUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/upload")

public class UploadController {

    @Autowired
    private OssUploadService ossUploadService;

    @PostMapping("/file")
    @ResponseBody
    public String upload(@RequestParam("file") MultipartFile multipartFile, HttpServletRequest request){

        if(multipartFile.isEmpty()){
            return "文件有误！！！";
        }

        //获取指定的文件夹
        String dir = "newHouseIssue";
        return ossUploadService.uploadFile(multipartFile, dir);
    }
}